package com.qf.contract.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.common.base.exception.ControllerException;
import com.qf.common.base.exception.ServiceException;
import com.qf.common.base.result.RespResult;
import com.qf.common.base.result.ResultCode;
import com.qf.contract.qo.FAnnouncementManagementQo;
import com.qf.contract.service.FAnnouncementManagementService;
import com.qf.contract.vo.FAnnouncementManagementListVo;
import com.qf.contract.vo.FAnnouncementManagementLookVo;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * 公告管理
 */
@Api(tags = "公告管理")
@RestController
@RequestMapping("/announcementmanagement")
public class AnnouncementManagementController {
    @Resource
    private FAnnouncementManagementService fAnnouncementManagementService;

    @ApiOperation("添加公告")
    @PutMapping("/addfannouncementmanagementservice")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "file", value = "需要上传的文件附件")
    })
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    public RespResult addFAnnouncementManagementService(FAnnouncementManagementQo fAnnouncementManagementQo, MultipartFile file) {
        try {
            return RespResult.success(fAnnouncementManagementService.addFAnnouncementManagementService(fAnnouncementManagementQo, file));
        } catch (ServiceException e) {
            throw new ServiceException(ResultCode.SYS_ERROR);
        } catch (Exception e) {
            throw new ControllerException(ResultCode.SYS_ERROR);
        }
    }

    /**
     * 删除公告
     *
     * @param id
     * @return
     */
    @ApiOperation("删除公告")
    @DeleteMapping("/detfannouncementmanagementservice")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "需要删除的公告的id")
    })
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    public RespResult detFAnnouncementManagementService(int id) {
        try {
            return RespResult.success(fAnnouncementManagementService.detFAnnouncementManagementService(id));
        } catch (ServiceException e) {
            throw new ServiceException(ResultCode.SYS_ERROR);
        } catch (Exception e) {
            throw new ControllerException(ResultCode.SYS_ERROR);
        }
    }

    /**
     * 编辑公告
     */
    @ApiOperation("编辑公告")
    @PutMapping("/updatefannouncementmanagementservice")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "file", value = "需要上传的文件附件")
    })
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    public RespResult updateFAnnouncementManagementService(FAnnouncementManagementQo fAnnouncementManagementQo, MultipartFile file) {
        try {
            return RespResult.success(fAnnouncementManagementService.updateFAnnouncementManagementService(fAnnouncementManagementQo, file));
        } catch (ServiceException e) {
            throw new ServiceException(ResultCode.SYS_ERROR);
        } catch (Exception e) {
            throw new ControllerException(ResultCode.SYS_ERROR);
        }
    }

    /*
    查看公告
     */
    @ApiOperation("查看公告")
    @GetMapping("/lookfannouncementmanagement")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "需要查看的文件id")
    })
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    public RespResult<FAnnouncementManagementLookVo> lookFAnnouncementManagement(int id) {
        try {
            return RespResult.success(fAnnouncementManagementService.lookFAnnouncementManagement(id));
        } catch (ServiceException e) {
            throw new ServiceException(ResultCode.SYS_ERROR);
        } catch (Exception e) {
            throw new ControllerException(ResultCode.SYS_ERROR);
        }
    }

    /**
     * 公告列表查看
     */
    @ApiOperation("公告列表查看")
    @GetMapping("/fAnnouncementManagementList")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "current", value = "页码"),
            @ApiImplicitParam(name = "size", value = "页数")
    })
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    public RespResult<IPage<FAnnouncementManagementListVo>> fAnnouncementManagementList(@RequestParam(defaultValue = "1") int current, @RequestParam(defaultValue = "10") int size) {
        try {
            return RespResult.success(fAnnouncementManagementService.fAnnouncementManagementList(current, size));
        } catch (ServiceException e) {
            throw new ServiceException(ResultCode.SYS_ERROR);
        } catch (Exception e) {
            throw new ControllerException(ResultCode.SYS_ERROR);
        }
    }


}
